<template>
<h1>注册页面</h1>
  <input type="text" placeholder="用户名" v-model="user.username">
  <input type="text" placeholder="密码" v-model="user.password">
  <input type="text" placeholder="昵称" v-model="user.nickname">
  <input type="button" value="注册" @click="reg()">
</template>

<script setup>
import axios from 'axios'
import {ref} from "vue";
import router from "@/router";

const user=ref({username:"",password:"",nickname:""})
const reg=()=>{
//  发出注册的请求
    axios.post('http://localhost:8080/v1/users/reg',user.value)
      .then((response)=>{
        //此处代码是服务器响应了之后执行, response代表响应对象里面包含服务器响应的数据
        //response.data 得到服务器Controller中return的内容(JsonResult对象)
        if (response.data.code==1){
          alert("注册成功");
          router.push('/');//跳转到首页
        }else {
          alert(response.data.msg)
        }
  })
}
</script>

<style scoped>

</style>